package kt_test.util

import android.content.Context
import android.util.Log
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import kt_test.model.OxygenUploadRequest
import java.io.IOException

object JsonLoader {
    fun loadOxygenData(context: Context): OxygenUploadRequest? {
        return try {
            val inputStream = context.assets.open("sample_oxygen_data.json")
            val jsonString = inputStream.bufferedReader().use { it.readText() }
            inputStream.close()

            val gson = Gson()
            val type = object : TypeToken<OxygenUploadRequest>() {}.type
            gson.fromJson(jsonString, type)
        } catch (e: IOException) {
            Log.e("JsonLoader", "读取 JSON 文件失败: ${e.message}")
            null
        }
    }
}
